package com.hitsz.application;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import com.hitsz.R;
import com.hitsz.global.Config;
import com.hitsz.global.UserInfor;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private Switch musicSwitch;
    private TextView stateText;
    Config conf = Config.getInstance();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 初始情况下默认是本地用户
        Config config = Config.getInstance();
        UserInfor userInfor= UserInfor.getInstance();

        // 如果未登陆则用户名默认本地用户
        if(!config.isLogin()){
            userInfor.setUserName("LocalUser");
        }


        // 显示当前状态
//        stateText = findViewById(R.id.stateText);
//        stateText.setText("当前用户： "+ userInfor.getUserName());
//        stateText.setTextColor(Color.RED);

        findViewById(R.id.to_login_button).setOnClickListener(this);
        findViewById(R.id.to_register_button).setOnClickListener(this);
        findViewById(R.id.exit_button).setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {

        if(view.getId() == R.id.to_login_button){
            // 登陆
            //Toast toast=Toast.makeText(this, "欢迎您，"+UserInfor.getInstance().getUserName()+"!",Toast.LENGTH_SHORT);
            //toast.show();

            // 跳转到登陆页面
            Intent intent = new Intent(MainActivity.this, LoginActivity.class);
            startActivity(intent);
        }
        else if(view.getId() == R.id.to_register_button){

            // 跳转到注册页面
            Intent intent = new Intent(MainActivity.this, RegisterActivity.class);
            startActivity(intent);

        }
        else if(view.getId() == R.id.exit_button){
            finish();
        }
        // 无论跳转到哪个界面都要结束当前界面
        this.finish();
    }



}